package com.example.demo_android;
import java.util.ArrayList;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

public class cls_sinhvien {
	String SO_BD;
	String TEN_SV;
	String DIA_CHI;
	String DIEM_THI;
	String MA_TRUONG;
	String NGAY_SINH;
	int ID;
	String TEN_TRUONG;
	String MA_SO;
	int flag=0;
	ArrayList<String>  arrtruong= new ArrayList<String>();
	String []arr;
	public cls_sinhvien GET_SINHVIEN_SBD() {
		//khoi tao cac hang so
		final String SOAP_ACTION = "http://tempuri.org/GET_SINHVIEN_SBD";
		final String METHOD_NAME = "GET_SINHVIEN_SBD";
		final String NAMESPACE = "http://tempuri.org";
		final String URL = "http://10.0.2.2/Phim/DEMO.asmx";
		int sodong=0;
		SoapObject table = null; //chua table cua dataset tra ve thong qua SoapObject
								
		SoapObject client = null; 
								
		SoapObject tableRow = null; 
		SoapObject responseBody = null; 
		SoapSerializationEnvelope sse = null; 
		//khoi tao SoapObject va cac tham so truyen vao 
		client = new SoapObject(NAMESPACE, METHOD_NAME);
		sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		sse.setOutputSoapObject(client);
		sse.addMapping(NAMESPACE, "cls_sinhvien", this.getClass());
		
		sse.dotNet = true;

		AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

		cls_sinhvien set_sv = new cls_sinhvien();
		try {
			
			
			sse.setOutputSoapObject(client);
			sse.bodyOut = client;
			androidHttpTransport.call(SOAP_ACTION, sse);
			responseBody = (SoapObject) sse.getResponse();
			//lay gia tri tra ve
			responseBody = (SoapObject) responseBody.getProperty(1);
			table = (SoapObject) responseBody.getProperty(0);
			//dem so dong co trong table
			if (table != null)
			{
				sodong=table.getPropertyCount();
			}
			for(int i=0;i<sodong;i++)
			{
				tableRow = (SoapObject) table.getProperty(i);
				String SDB_CL=tableRow.getProperty("ma_sinhvien").toString();
				String tentruong=tableRow.getProperty("ten_truongthi").toString();;
				if(TEN_TRUONG.toUpperCase().equals(tentruong.toUpperCase()) && MA_SO.toUpperCase().equals(SDB_CL.toUpperCase()))
				{
					set_sv.SO_BD = tableRow.getProperty("ma_sinhvien").toString();
					set_sv.TEN_SV = tableRow.getProperty("hoten_sinhvien").toString();
					set_sv.DIEM_THI = tableRow.getProperty("diemthi").toString();
					set_sv.NGAY_SINH=tableRow.getProperty("ngaysinh").toString();
					set_sv.MA_TRUONG=tableRow.getProperty("ma_truongthi").toString();
					set_sv.flag=1;
				}
				
			}
		} catch (Exception e) 
		{
			set_sv.flag=0;
		}
		return set_sv;
	}
	public cls_sinhvien GET_TENTRUONG() {
		//khoi tao cac hang so
		final String SOAP_ACTION = "http://tempuri.org/GET_SINHVIEN_SBD";
		final String METHOD_NAME = "GET_SINHVIEN_SBD";
		final String NAMESPACE = "http://tempuri.org";
		final String URL = "http://10.0.2.2/Phim/DEMO.asmx";
		int sodong=0;
		SoapObject table = null; //chua table cua dataset tra ve thong qua SoapObject
		SoapObject client = null; 
		SoapObject tableRow = null; 
		SoapObject responseBody = null; 
		SoapSerializationEnvelope sse = null; 
		//khoi tao SoapObject va cac tham so truyen vao 
		client = new SoapObject(NAMESPACE, METHOD_NAME);
		sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		sse.setOutputSoapObject(client);
		sse.addMapping(NAMESPACE, "cls_sinhvien", this.getClass());
		sse.dotNet = true;
		cls_sinhvien set_sv = new cls_sinhvien();
		AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
		try {
			sse.setOutputSoapObject(client);
			sse.bodyOut = client;
			androidHttpTransport.call(SOAP_ACTION, sse);
			responseBody = (SoapObject) sse.getResponse();
			//lay gia tri tra ve
			responseBody = (SoapObject) responseBody.getProperty(1);
			table = (SoapObject) responseBody.getProperty(0);
			//dem so dong co trong table
			if (table != null)
			{
				sodong=table.getPropertyCount();
			}
			for(int i=0;i<sodong;i++)
			{
				tableRow = (SoapObject) table.getProperty(i);
				//dua gia tri vao mang
				set_sv.TEN_TRUONG=tableRow.getProperty("ten_truongthi").toString();
				set_sv.arrtruong.add(set_sv.TEN_TRUONG.toString());		
			}
			set_sv.arr = new String[set_sv.arrtruong.size()];
			set_sv.arr = set_sv.arrtruong.toArray(set_sv.arr);			
		} catch (Exception e) 
		{
		}
		return set_sv;
	}

	
}
